package com.zis.auction.controller;

import com.alibaba.fastjson.JSON;
import com.zis.auction.model.AuctBid;
import com.zis.auction.service.IAuctBidInter;
import com.zis.core.SearchParams;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by wangshen 2017/12/28
 */
@RestController
@RequestMapping("/api/auction/bid")
public class AuctBidController {

    @Autowired
    private IAuctBidInter auctBidInter;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public PageQuery<AuctBid> findByPage(@RequestBody SearchParams params) throws Exception {
        return auctBidInter.findByPage(params);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String insert(HttpServletRequest request, @RequestBody AuctBid auctBid) throws Exception {
        auctBid.setCreateUser(request.getAttribute("code").toString());
        return auctBidInter.insert(auctBid);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(HttpServletRequest request, @RequestBody AuctBid auctBid) throws Exception {
        auctBid.setUpdateUser(request.getAttribute("code").toString());
        return auctBidInter.update(auctBid);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable("id") String id) throws Exception{
        return auctBidInter.delete(id);
    }

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public AuctBid select(@PathVariable("id") String id) throws Exception{
        return auctBidInter.selectById(id);
    }
}
